package com.hanter.downloader.exception;

import com.hanter.downloader.Response;

/**
 * 文件名：ResponseException <br/>
 * 描述：未处理的HTTP状态，抛出此异常。包含自定义的异常情况，具体错误 getCause() 获取
 * 创建时间：2022/02/09 15:00
 *
 * @author wangmingshuo
 * @version 1.0
 */
public class ResponseException extends RuntimeException {

    public static final int ERR_CANCEL = -1;
    public static final int ERR_INTERRUPT = -2;
    public static final int ERR_FAILED = -3;

    /**
     * HTTP code，200 301 等
     */
    private final int code;

    public ResponseException(Response res) {
        this(res.getCode(), res.getMessage(), res.getThrowable());
    }

    public ResponseException(int code) {
        this.code = code;
    }

    public ResponseException(int code, String message) {
        super(message);
        this.code = code;
    }

    public ResponseException(int code, Throwable cause) {
        super(cause);
        this.code = code;
    }

    public ResponseException(int code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
    }

    public int getCode() {
        return code;
    }
}
